package com.bdqn.config;

import com.bdqn.component.ParamterAndAcceptHeaderLocaleResolver;
import com.bdqn.intercepts.LoginHandlerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
import org.springframework.web.servlet.i18n.FixedLocaleResolver;


@Configuration
    public class AppExtendConfig implements WebMvcConfigurer {


    @Autowired
    private WebMvcProperties mvcProperties;

    /**
     * 自定的国际化组件 延续了之前的AcceptHeaderLocaleResolver特点增加了参数lang设置语言
     * 如果不适用请注释掉此方法
     * @return
     */
    @Bean
    public LocaleResolver localeResolver() {
        if (this.mvcProperties.getLocaleResolver() == WebMvcProperties.LocaleResolver.FIXED) {
            return new FixedLocaleResolver(this.mvcProperties.getLocale()); 111
        }
        AcceptHeaderLocaleResolver localeResolver = new ParamterAndAcceptHeaderLocaleResolver();
        localeResolver.setDefaultLocale(this.mvcProperties.getLocale());
        return localeResolver;
    }



    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/login.html","/emp/login","/css/**","/images/**","/js/**","/layui/**");


    }
}
